package batch.RusSieDaemon;
import java.io.File;
import java.io.FilenameFilter;
import java.util.regex.Pattern;
 
public class FilenameFilterTest implements FilenameFilter
{
    private String filter;
 
    public FilenameFilterTest(String filter)
    {
        this.filter = filter;
    }
 
    public boolean accept(File dir, String name)
    {
        String filter = this.filter
            .replaceAll("\\.", "\\\\.")
            .replaceAll("\\$", "\\\\$")
            .replaceAll("\\+", "\\\\+")
            .replaceAll("\\(", "\\\\(")
            .replaceAll("\\)", "\\\\)")
            .replaceAll("\\{", "\\\\{")
            .replaceAll("\\}", "\\\\}")
            .replaceAll("\\[", "\\\\[")
            .replaceAll("\\]", "\\\\]")
            .replaceAll("\\^", "\\\\^")
            .replaceAll("\\*", ".*")
            .replaceAll("\\?", ".");
 
        return Pattern.matches(filter, name);
    }
 
 
}

